﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Microsoft.WowAddonStudio.TocEditor
{
	/// <summary>
	/// Editor dialog for adding and editing custom tags.
	/// </summary>
	public partial class TagEditorDialog : Form
	{
		public string TagName { get; set; }
		public string TagValue { get; set; }

		/// <summary>
		/// Initializes a new instance of the <see cref="TagEditorDialog"/> class.
		/// </summary>
		public TagEditorDialog()
		{
			InitializeComponent();
			tagNameComboBox.DataSource = new List<string>(TocTagName.GetCommonTagNames());
		}

		/// <summary>
		/// Handles the Load event of the TagEditorDialog control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private void TagEditorDialog_Load(object sender, EventArgs e)
		{
			if (!string.IsNullOrEmpty(TagName))
			{
				if (tagNameComboBox.Items.Contains(TagName))
					tagNameComboBox.SelectedItem = TagName;
				else
					tagNameComboBox.Text = TagName;
			}

			tagValueTextBox.Text = TagValue;
		}

		/// <summary>
		/// Handles the Click event of the okButton control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private void okButton_Click(object sender, EventArgs e)
		{
			TagName = tagNameComboBox.Text;
			TagValue = tagValueTextBox.Text;

			DialogResult = DialogResult.OK;
			Close();
		}

		/// <summary>
		/// Handles the Click event of the cancelButton control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private void cancelButton_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
			Close();
		}
	}
}